package it.webrules.deploymanager.core.utils;

import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * Classe con metodi di utilità statici.
 * Classe non istanziabile.
 * 
 * @author dometec
 *
 */
public final class CollectionUtils {

	private CollectionUtils() {
	}

	@SuppressWarnings("rawtypes")
	public static String print(Map map) {
		return print(map.entrySet());
	}

	@SuppressWarnings("rawtypes")
	public static String print(Set set) {

		StringBuilder out = new StringBuilder();

		Iterator iterator = set.iterator();

		while (iterator.hasNext()) {

			Object key = iterator.next();
			out.append(key + "=");

			Object value = key;
			if (value instanceof String[]) {
				for (String val : (String[]) value) {
					out.append("{" + val + ", ");
				}
				out.deleteCharAt(out.length() - 1);
				out.deleteCharAt(out.length() - 1);
				out.append("}");
			} else {
				out.append(value);
			}

			if (iterator.hasNext())
				out.append(", ");
		}

		return out.toString();

	}

	@SuppressWarnings("rawtypes")
	public static String print(List list) {

		StringBuilder out = new StringBuilder("(");

		for (Object object : list) {
			out.append(object);
			out.append(", ");
		}

		if (list.size() > 0)
			out.delete(out.length() - 2, out.length());

		out.append(")");

		return out.toString();

	}
}
